package com.yao.mybatis.config;

import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

/**
 * mybatis 唯一配置类
 *
 * @author Administrator
 */
public class Configuration {
    /**
     * 存放mysql连接信息
     */
    private DataSource dataSource;
    /**
     * 存放每个sql语句和statement映射
     */
    private Map<String, MappedStatement> mappedStatementMap = new HashMap<>();

    public DataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    public Map<String, MappedStatement> getMappedStatementMap() {
        return mappedStatementMap;
    }

    public void setMappedStatementMap(Map<String, MappedStatement> mappedStatementMap) {
        this.mappedStatementMap = mappedStatementMap;
    }

    /**
     * 往集合中添加MappedStatement
     *
     * @param key
     * @param mappedStatement
     */
    public void addStatement(String key, MappedStatement mappedStatement) {
        this.mappedStatementMap.put(key, mappedStatement);
    }

    /**
     * 从集合中取出MappedStatement
     *
     * @param key
     * @return
     */
    public MappedStatement getMappedStatement(String key) {

        return mappedStatementMap.get(key);

    }
}
